
import java.util.Scanner;

/**
 * @program: javase
 * @description: 登录，注册，抽奖
 * @author: lld
 * @create: 2020/08/26 10:20
 **/
public class Lottery {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String yes = "y";
        String name = null;
        String password = null;
        boolean isRegister = false;
        boolean isLogin = false;
        int random = 0;
        do {
            System.out.println("*******欢迎进入大富翁系统********");
            System.out.println("1.注册");
            System.out.println("2.登录");
            System.out.println("3.抽奖");
            System.out.println("********************************");
            System.out.println("请选择菜单：");
            int i = scanner.nextInt();
            switch (i) {
                case 1:
                    System.out.println("【大富翁系统】>>>【注册】");
                    System.out.println("请填写用户名，密码信息：");
                    System.out.print("用户名：");
                    name = scanner.next();
                    System.out.print("密码：");
                    password = scanner.next();
                    random = (int) ((Math.random() * 9 + 1) * 1000);
                    System.out.println();
                    if (!name.equals("") && !password.equals("")) {
                        isRegister = true;
                        System.out.println("注册成功，请记住您的会员卡号");
                        System.out.printf("用户名\t密码\t卡号\t\n");
                        System.out.printf("%s\t\t%s\t\t%d\t\t\n", name, password, random);
                    }
                    break;
                case 2:
                    System.out.println("【大富翁系统】>>>【登录】");
                    System.out.println("请输入用户名和密码：");
                    System.out.print("用户名：");
                    String name1 = scanner.next();
                    System.out.print("密码：");
                    String password1 = scanner.next();
                    if (isRegister) {
                        if (name1.equals(name) && password1.equals(password)) {
                            isLogin = true;
                            System.out.println("登录成功");
                        } else {
                            System.out.println("用户名或密码错误");
                        }
                    } else {
                        System.out.println("请先注册");
                    }
                    break;
                case 3:
                    System.out.println("【大富翁系统】>>>【抽奖】");
                    if (isLogin) {
                        System.out.print("请输入会员卡号：");
                        int random1 = scanner.nextInt();
                        if (random1 == random) {
                            //生成5个4位随机数字，并保存在数组中
                            int[] randoms = new int[5];
                            for (int j = 0; j < 5; j++) {
                                randoms[j] = (int) ((Math.random() * 9 + 1) * 1000);
                            }
                            System.out.print("本日幸运用户卡号为：");
                            for (int r1 : randoms) {
                                System.out.printf("%d\t", r1);
                            }
                            System.out.println();
                            for (int r = 0; r < randoms.length; r++) {
                                if (r == random1) {
                                    System.out.println("恭喜你成为本日幸运用户");
                                    break;
                                }
                                if (r == randoms.length - 1) {
                                    System.out.println("很遗憾，本日幸运用户没有你");
                                }
                            }
                        } else {
                            System.out.println("该会员卡号不存在，请重新输入");
                        }
                    } else {
                        System.out.println("请先登录");
                    }
                    break;
                default:
                    System.out.println("请重新选择菜单");
                    break;
            }
            System.out.println("继续吗（y/n)?");
            yes = scanner.next();
        } while (yes.equals("y"));
        if (yes.equals("n")) {
            System.out.println("退出成功");
        }
    }
}
